class Walking3 extends egret.Sprite {
    private segment0: Segment
    private segment1: Segment
    private offset: number = -1.57

    private cycle: number = 0
    public constructor() {
        super()
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this)
    }

    private onAddToStage(event: egret.Event) {
        this.segment0 = new Segment(100, 20)
        this.addChild(this.segment0)
        this.segment0.x = 200
        this.segment0.y = 120

        this.segment1 = new Segment(100, 20)
        this.addChild(this.segment1)
        this.segment1.x = this.segment0.getPin().x
        this.segment1.y = this.segment0.getPin().y

        this.addEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this)
    }

    private onEnterFrame() {
        this.cycle += 0.05
        let angle0: number = Math.sin(this.cycle) * 45 + 90
        let angle1: number = Math.sin(this.cycle + this.offset) * 45 + 45
        this.segment0.rotation = angle0
        this.segment1.rotation = angle1 + this.segment0.rotation
        this.segment1.x = this.segment0.getPin().x
        this.segment1.y = this.segment0.getPin().y
    }
}